<?php

namespace app\teacher\model;

use app\common\model\BaseModel;
use think\Model;

class UserFile extends BaseModel
{
    protected $autoWriteTimestamp = 'int';
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';

    /**
     * 上传课件
     */
    public static function add($userIds, $teacherFileId)
    {
        $files = TeacherFile::getFiles($teacherFileId);
        if (!$files) {
            static::errorMsg(20003);
        }
        $data = [];
        foreach ($userIds as $v) {
            foreach ($files as $val) {
                $data[] = [
                    'user_id' => $v,
                    'teacher_id' => $val->teacher_id,
                    'filename' => $val->filename,
                    'size' => $val->size,
                    'file' => $val->file,
                    'createtime' => time(),
                    'updatetime' => time()
                ];
            }
        }
        return self::insertAll($data);
    }


}
